package com.heima.media.controller;

import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.WmMaterialDto;
import com.heima.media.service.IWmMaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 自媒体图文素材信息表 前端控制器
 * </p>
 *
 * @author DJC
 */
@RestController
@RequestMapping("/api/v1/material")
@Api(tags = "自媒体图文素材信息表接口")
@CrossOrigin
public class WmMaterialController {

    @Autowired
    private IWmMaterialService wmMaterialService;


    @PostMapping("/upload_picture")
    @ApiOperation(value = "saveWmMaterial", notes = "素材上传")
    @ApiModelProperty(name = "file", dataType = "MultipartFile", required = true)
    public ResponseResult upload(MultipartFile file) {
        return wmMaterialService.saveWmMaterial(file);
    }

    @PostMapping("/list")
    @ApiOperation(value = "listByPage", notes = "素材列表展示")
    @ApiModelProperty(name = "dto", dataType = "WmMaterialDto", required = true)
    public ResponseResult list(@RequestBody WmMaterialDto dto) {
        return wmMaterialService.listByPage(dto);
    }

    @PutMapping("/collect/{id}")
    public ResponseResult Collect(@PathVariable("id") Integer id) {
        return wmMaterialService.updatecollect(id, 1);
    }

    @PutMapping("/cancel_collect/{id}")
    public ResponseResult canacelCollect(@PathVariable("id") Integer id) {
        return wmMaterialService.updatecollect(id, 2);
    }

    @DeleteMapping("/{id}")
    public ResponseResult delect(@PathVariable("id") Integer id) {
        wmMaterialService.removeById(id);
        return ResponseResult.okResult();
    }
}


